﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;
using MySql.EntityFrameworkCore.Metadata;

#nullable disable

namespace MododorWebAPI.Migrations
{
    /// <inheritdoc />
    public partial class m1 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AlterDatabase()
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "Company",
                columns: table => new
                {
                    id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn),
                    IdCompany = table.Column<long>(type: "bigint", nullable: false),
                    CompanyNameCh = table.Column<string>(type: "longtext", nullable: true),
                    CompanyNameEn = table.Column<string>(type: "longtext", nullable: true),
                    CompanyZip = table.Column<int>(type: "int", nullable: true),
                    CompanyCity = table.Column<string>(type: "longtext", nullable: true),
                    CompanyAdd = table.Column<string>(type: "longtext", nullable: true),
                    CompanyTel = table.Column<string>(type: "longtext", nullable: true),
                    CompanyDate = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    CompanyEnable = table.Column<bool>(type: "bit(1)", nullable: true, defaultValue: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Company", x => x.id);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "ContractType",
                columns: table => new
                {
                    idContractType = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn),
                    ContractTypeName = table.Column<string>(type: "longtext", nullable: true),
                    ContractTypeDescription = table.Column<string>(type: "longtext", nullable: true),
                    ContractTypeEN = table.Column<bool>(type: "bit(1)", nullable: true, defaultValue: true),
                    ContractTypeDate = table.Column<DateTime>(type: "datetime(6)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ContractType", x => x.idContractType);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "User",
                columns: table => new
                {
                    idUser = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn),
                    UserName = table.Column<string>(type: "longtext", nullable: false),
                    UserEmail = table.Column<string>(type: "longtext", nullable: true),
                    UserPassword = table.Column<string>(type: "longtext", nullable: false),
                    UserKey = table.Column<long>(type: "bigint", nullable: false),
                    UserEnable = table.Column<bool>(type: "bit(1)", nullable: true, defaultValue: true),
                    UserIV = table.Column<long>(type: "bigint", nullable: false),
                    UserCreateDate = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    UserRole = table.Column<int>(type: "int", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_User", x => x.idUser);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "Client",
                columns: table => new
                {
                    idClient = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn),
                    ClientNameCh = table.Column<string>(type: "longtext", nullable: true),
                    ClientNameEn = table.Column<string>(type: "longtext", nullable: true),
                    ClientEmail = table.Column<string>(type: "longtext", nullable: true),
                    ClientMobile = table.Column<string>(type: "longtext", nullable: true),
                    ClientJobTitle = table.Column<string>(type: "longtext", nullable: true),
                    ClientEN = table.Column<bool>(type: "bit(1)", nullable: true, defaultValue: true),
                    ClientDate = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    Client_idCompanyid = table.Column<long>(type: "bigint", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Client", x => x.idClient);
                    table.ForeignKey(
                        name: "FK_Client_Company_Client_idCompanyid",
                        column: x => x.Client_idCompanyid,
                        principalTable: "Company",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "Contract",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn),
                    idContract = table.Column<long>(type: "bigint", nullable: false),
                    ContractStartDate = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    ContractEndDate = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    ContractTypeidContractType = table.Column<long>(type: "bigint", nullable: false),
                    ContractEnable = table.Column<bool>(type: "bit(1)", nullable: true, defaultValue: true),
                    ContractDate = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    ContractCompanyIDid = table.Column<long>(type: "bigint", nullable: false),
                    ContractActive = table.Column<bool>(type: "bit(1)", nullable: true),
                    ContractContent = table.Column<string>(type: "longtext", nullable: true),
                    ContracDelivery = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    ContractHours = table.Column<int>(type: "int", nullable: true, defaultValue: 0),
                    ContractName = table.Column<string>(type: "longtext", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Contract", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Contract_Company_ContractCompanyIDid",
                        column: x => x.ContractCompanyIDid,
                        principalTable: "Company",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_Contract_ContractType_ContractTypeidContractType",
                        column: x => x.ContractTypeidContractType,
                        principalTable: "ContractType",
                        principalColumn: "idContractType",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "ClientModelContractModel",
                columns: table => new
                {
                    ClientModelsidClient = table.Column<long>(type: "bigint", nullable: false),
                    ContractsId = table.Column<long>(type: "bigint", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ClientModelContractModel", x => new { x.ClientModelsidClient, x.ContractsId });
                    table.ForeignKey(
                        name: "FK_ClientModelContractModel_Client_ClientModelsidClient",
                        column: x => x.ClientModelsidClient,
                        principalTable: "Client",
                        principalColumn: "idClient",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_ClientModelContractModel_Contract_ContractsId",
                        column: x => x.ContractsId,
                        principalTable: "Contract",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_Client_Client_idCompanyid",
                table: "Client",
                column: "Client_idCompanyid");

            migrationBuilder.CreateIndex(
                name: "IX_ClientModelContractModel_ContractsId",
                table: "ClientModelContractModel",
                column: "ContractsId");

            migrationBuilder.CreateIndex(
                name: "IX_Company_IdCompany",
                table: "Company",
                column: "IdCompany",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_Contract_ContractCompanyIDid",
                table: "Contract",
                column: "ContractCompanyIDid");

            migrationBuilder.CreateIndex(
                name: "IX_Contract_ContractTypeidContractType",
                table: "Contract",
                column: "ContractTypeidContractType");

            migrationBuilder.CreateIndex(
                name: "IX_Contract_idContract",
                table: "Contract",
                column: "idContract",
                unique: true);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "ClientModelContractModel");

            migrationBuilder.DropTable(
                name: "User");

            migrationBuilder.DropTable(
                name: "Client");

            migrationBuilder.DropTable(
                name: "Contract");

            migrationBuilder.DropTable(
                name: "Company");

            migrationBuilder.DropTable(
                name: "ContractType");
        }
    }
}
